package outputAdapters;

import inputs.Input;

public class MiddleAdapter extends OutputAdapter{
	
	public MiddleAdapter(Range outputType)
	{
		super(outputType);
	}
	
	public MiddleAdapter(Range outputType, Input input)
	{
		super(outputType, input);
		
	}
	
	protected void Update() {
		int offsetMax = input.getMax() - input.getMin();
		float middle = (float) offsetMax / 2;
		float first = (float) middle / 2;
		float third = (float) (offsetMax + middle) / 2;
		
		third -= first;
		
		float offsetVal = input.getValue() - input.getMin() - first;
		
		float val = (float) offsetVal / third;
		//float val = (float) ((input.getValue() - input.getMin()) / (input.getMax() - input.getMin()));
		if (val < 0)
			value = outputRange.getMin();
		else
		{
			if (val > 1)
				value = outputRange.getMax();
			else
				value = (int) ((val * (outputRange.getMax() - outputRange.getMin())) + outputRange.getMin());
		}
	}
}
